/*****************************
 * Class Registration System *
 * Javascript				 *
 * CPSC 462					 *
 * Coded by: Trent Robbins	 *
 ****************************/
 
$(document).ready(function(){
	$('#loginForm').validate();	
});

$(document).ready(function(){
	$('#picUploadForm').validate();	
});
$(document).ready(function(){
	$('#newUserForm').validate();	
});
$(document).ready(function() { 

	var options = { 
		success:		showResponse,	// post-submit callback 
		beforeSubmit:	disableSubmit,
		resetForm:		true,        	// reset the form after successful submit 
		error:			enableSubmit
 	}; 

	// bind to the form's submit event 
	$('#loginForm').submit(function() {  
		if ($('#loginForm').validate().numberOfInvalids()==0) {
			$(this).ajaxSubmit(options); 
		}
		//return false to prevent standard browser submit and page navigation 
		return false; 
	}); 

}); 

$(document).ready(function() { 

	var options = { 
		success:		showPic,	// post-submit callback 
		beforeSubmit:	disableSubmit,
		resetForm:		true,        	// reset the form after successful submit 
		error:			enableSubmit
 	}; 

	// bind to the form's submit event 
	$('#picUploadForm').submit(function() {  
		if ($('#picUploadForm').validate().numberOfInvalids()==0) {
			$(this).ajaxSubmit(options); 
		}
		//return false to prevent standard browser submit and page navigation 
		return false; 
	}); 

}); 

$(document).ready(function() { 

	var options = { 
		success:		showResult,	// post-submit callback 
		beforeSubmit:	disableSubmit,
		resetForm:		true,        	// reset the form after successful submit 
		error:			enableSubmit
 	}; 

	// bind to the form's submit event 
	$('#newUserForm').submit(function() {  
		if ($('#newUserForm').validate().numberOfInvalids()==0) {
			$(this).ajaxSubmit(options); 
		}
		//return false to prevent standard browser submit and page navigation 
		return false; 
	}); 

}); 

function showPic(responseText, statusText)  { 
	$('#studImage').html(responseText);
	$('#uploadButton').removeAttr("disabled");
} 

function showResponse(responseText, statusText)  { 
	$('#loginErr').html(responseText);
	$('#loginButton').removeAttr("disabled");
} 

function showResult(responseText, statusText){
	$('#submitResult').html(responseText);
	$('#newUserSave').removeAttr("disabled");
}

function enableSubmit(xmlr) {
	$('#loginButton').removeAttr("disabled");
	$('#uploadButton').removeAttr("disabled");
	$('#newUserSave').removeAttr("disabled");
	ajaxerror(xmlr);
}

function disableSubmit() {
	$('#loginButton').attr("disabled", "true");
	$('#uploadButton').attr("disabled", "true");
	$('#newUserSave').attr("disabled", "true");

}

function dropCheck(){
	var goAhead = confirm("Are you sure you want to Drop this class?");
	if(goAhead){
		return true;
	}
	else{
		return false;
	}
}

function dropRequest(){
	var goAhead = confirm("Are you sure you want to UnRequest this class?");
	if(goAhead){
		return true;
	}
	else{
		return false;
	}
}

function deleteStud(){
	var goAhead = confirm("Are you sure you want to delete this user?");
	if(goAhead){
		return true;
	}
	else{
		return false;
	}
}